package com.leetcode.algorithm.y22.m07;

/**
 * 387. 字符串中的第一个唯一字符
 * 
 * https://leetcode.cn/problems/first-unique-character-in-a-string/
 * 
 * @author jie.deng
 *
 */
public class Question0387Solution01 {

	public int firstUniqChar(String s) {
		int[] cntArr = new int[26];
		for (int i = 0; i < s.length(); i++) {
			cntArr[s.charAt(i) - 'a']++;
		}
		for (int i = 0; i < s.length(); i++) {
			if (cntArr[s.charAt(i) - 'a'] == 1) {
				return i;
			}
		}
		return -1;
	}

}
